<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px" @submit.native.prevent>
      <el-form-item label="文件名称" prop="userName">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入文件名称"
          clearable
          @clear="handleQuery"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading"
              :data="listFile">
      <el-table-column label="文件名" align="center" prop="name" width="220" />
      <el-table-column label="下载地址" align="center" prop="url" width="300" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <i class="el-icon-document-copy" v-clipboard:copy="scope.row.url" v-clipboard:success="copyText" style="margin-right: 5px;cursor: pointer;"></i>
          {{ scope.row.url }}
        </template>
      </el-table-column>
      <el-table-column label="扩展名" align="center" prop="expandName" width="90" />
      <el-table-column label="原文件名" align="center" prop="oldName"/>
      <el-table-column label="文件大小" align="center" prop="fileSize" width="100"/>
      <el-table-column label="类型" align="center" prop="fileType" width="130" />
      <el-table-column label="创建人" align="center" prop="authorUser" width="120" />
      <el-table-column label="创建日期" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listFile} from "@/api/platform/file/file";

export default {
  name: "File",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //获取的目录列表
      listFile:[],
      // 弹出层标题
      title: "",
      // 是否显示添加修改弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询模板列表 */
    getList() {
      this.loading = true;
      //默认第一层级的数据
      listFile(this.queryParams).then(response => {
        this.listFile = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    copyText(){
      this.$message.success("复制成功")
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams={}
      this.handleQuery();
    }
  }
};
</script>
